extends "../cTDA/cTDA.gd"
func _info():
	pass

func _connect():
	._connect()

var norcnt:int = 0
var tlv = 0
var nlv = 0
var spw1 = 0.5
var spw2 = 10
var spw3 = 1.15

func _extInit():
	._extInit()
	#chaName = "圣剑客·Lv[0]"
	lv = 4
	attCoe.atkRan = 2
	attCoe.atk = 30 / 8.5 * 2 / 4
	attCoe.maxHp = 450 / 112.5 / 4
	attAdd.cri = 0.05
	attAdd.criR = 0.5
	attCoe.pen = 20
	addCdSkill("hyzr",4)
	addSkillTxt("幻影之刃：暴击+5%，爆伤+50%；普攻击中时附带敌方血量上限4%真伤(不高于5倍自身攻击)|开局使用幻影散射[如果解锁了]")#开局使用幻影散射
	addSkillTxt("幻影散射：扔出6把匕首随机攻击6个敌人（不重复），每把造成<50+2*技能等级>%物攻真伤，随后瞬移到攻击到的最远的敌人附近并对其再次造成一次伤害[cd:4秒][color=#666666][未解锁][/color]")#对随机6个敌人造成<50+2*技能等级>真伤，随后移动到最远那个并对其再次造成伤害
	addSkillTxt("刺客本能：普攻有<10+技能等级*2>%再普攻一次[可无限连击]|<固化>每2秒添加1层<模糊>[color=#666666][未解锁][/color]")#原+每2秒添加1层模糊<固化>
	addSkillTxt("弱点增伤：普攻与幻影散射有20%概率使伤害翻倍|敌方若有护甲则伤害增加<15+技能等级>%，若有护盾则伤害增加50%[color=#666666][未解锁][/color]")#原+穿透+20
	addSkillTxt("[color=red]Tips:杀人会获得经验，战斗结束后会计算经验并升级;升级获得的属性和解锁的技能及等级全局有效")
	nlv = 0
	lvup()
	if skill3unlock:
		skillunlock(3)
	if skill2unlock:
		skillunlock(2)
	if skill1unlock:
		skillunlock(1)

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "hyzr" && skill1unlock:
		cst("幻影散射","000000",position)
		hyss()

func _onBattleStart():
	._onBattleStart()
	norcnt = 0
	if skill1unlock:
		hyss()
	if sys.test:
		lvup()
		if !skill3unlock:
			#print("unlock3")
			skillunlock(3)

func _onAtkChara(atkinfo):
	if atkinfo.atkType != Chara.AtkType.EFF && !atkinfo.isMiss:
		if skill3unlock:
			if atkinfo.hitCha.att.def + atkinfo.hitCha.att.mgiDef != 0:
				skill3up()
				atkinfo.hurtVal *= spw3

			if atkinfo.hitCha.get("shield") != null:
				if atkinfo.hitCha.get("shield")  > 0:
					atkinfo.hurtVal *= 1.5

	if atkinfo.atkType == Chara.AtkType.NORMAL && atkinfo.hitCha != self && atkinfo.atkCha == self:
		if !atkinfo.isMiss:
			var dmg = atkinfo.hitCha.att.maxHp * 0.04
			if dmg > att.atk * 5: dmg = att.atk * 5
			hurtChara(atkinfo.hitCha,dmg,Chara.HurtType.REAL,Chara.AtkType.EFF)
			

		if skill2unlock:
			skill2up()
			if sys.rndPer(spw2):
				hurtChara(atkinfo.hitCha,att.atk,Chara.HurtType.PHY,Chara.AtkType.NORMAL)

		if skill3unlock && sys.rndPer(20):
			atkinfo.hurtVal *=2
			
	._onAtkChara(atkinfo)

func _upS():
	._upS()
	if !skill2unlock:return
	norcnt += 1
	if norcnt == 2:
		norcnt = 0
		addBuff(ctrl.b_vague.new(1))

func hyss():
	skill1up()
	if sys.rndPer(20) && skill3unlock:
		spw1 *= 2 
	var chas = getAllChas(1)
	var chas2 = []
	for i in range(6):
		if !chas.size():break
		var tmp  =  sys.rndListItem(chas)
		chas2.append(tmp)
		chas.remove(chas.find(tmp))
	chas2.sort_custom(self,"sortbydis")
	for i in chas2:
		hurtChara(i,att.atk * spw1,Chara.HurtType.REAL,Chara.AtkType.SKILL)
	if chas2[0]:
		jump(chas2[0],self)
		hurtChara(chas2[0],att.atk * spw1,Chara.HurtType.REAL,Chara.AtkType.SKILL)
#战后计算经验
func _onBattleEnd():
	._onBattleEnd()
	yield(reTimer(0.01),"timeout")
	lvup()
	upAtt()
#升级改名改等级
func lvup():

	#if chaName.find("Lv[") == -1:
	#	nlv = 0
	#else:
	#	nlv = int(chaName.right(chaName.find("[")).left(2))
		
	if killNum >= 2:
		tlv = 1
	var e = 2
	var k = 3
	while(killNum >= e + k):
		tlv += 1
		e = e + k
		k += 1
	if sys.test:tlv = nlv + 1
	tlv = min(18,tlv)
	if tlv > nlv:
		upattadd(tlv,nlv)
		nlv = tlv
	chaName = "幻影之刃·Lv[" + str(nlv) + "]"
#升级修改属性
func upattadd(tlv,nlv):
	attAdd.atk += (tlv - nlv) * 5
	attAdd.maxHp += (tlv - nlv) * 63
	attAdd.spd += (tlv - nlv) * 0.02
	#attAdd.cri += (tlv - nlv) * 0.01
	attAdd.criR += (tlv - nlv) * 0.02
	healCha(self,(tlv - nlv) * 10)
#修改技能1系数
func skill1up():
	spw1 = 0.5 + skill1lv * 0.02
#修改技能2系数
func skill2up():
	spw2 = 10 + skill2lv * 2
#修改技能3系数
func skill3up():
	spw3 = 1.1 + skill3lv * 0.01
func sortbydis(a,b):
	return dis(a.cell,cell) > dis(b.cell,cell)